// 女仆极限解析
// 武器推荐  骨剑>白影  天空(充能强一点)>无工/狼末
// 90级面板
// 白值:191, 暴击率:5, 暴击伤害:50, 防御力:799 防御百分比:30%

// 命座效果 重击体力消耗减少20% 增伤15      盾消失时造成攻击力x4岩伤   大招多加50%防御力的攻击力 延长时间10s(需要砍人)

// 圣遗物选择角斗士4  攻击力18% 普攻增伤35%
// 初始副词条取最优 攻防双爆 (双爆>防御百分比>攻击百分比>防御固定值)  // 副词条效果与主词条效果不重复 每个圣遗物5次强化副词条全排列取最优结果 

// 单人输出手法 qaaaa eaaaa aaaa aaaa  大概15s

// 下面伤害都是算的暴击期望平均伤害  天赋取10级

// 天空之傲 674面板 16增伤 充能36.8 大招后8次真空刃 攻击力x1.6 物理伤害 
// 圣遗物 防御 岩伤 暴击    副词条强化搭配   暴击率:46.8(12)  暴击伤害:101.4(13) 
// 数值 攻击力 1582+2176=3758  暴击98.5  爆伤190.4 防御力:1783
// 46.6岩增伤   35普攻增伤(角斗士) 16武器增伤
// e开盾 8106
// q爆发 22776
// 普攻一套 66890
// 盾消失 31633
// 真空刃 72216
// 总 330078 + 72216     加上真空刃看起来伤害高 但女仆大招能持续25秒 真空刃后面发不出来就比不过其他了


// 狼末跟无工 608面板 49.6攻击 40攻击 // 额外特效无工40攻击  狼末80攻击
// 圣遗物 防御 岩伤 暴击    副词条强化搭配   暴击率:46.8(12)  暴击伤害:101.4(13) 
// 数值 攻击力 2201+2176=4377  暴击98.5  爆伤190.4 防御力:1783
// 46.6岩增伤   35普攻增伤(角斗士) 
// e开盾 7308
// q爆发 23916
// 普攻一套 71595
// 盾消失 33216
// 总 350825    无工一直有盾:375904   狼末一直有buff:400982


// 白影 510面板 48攻击 99.7防御百分比
// 圣遗物 防御 岩伤 暴击    副词条强化搭配   暴击率:46.8(12)  暴击伤害:101.4(13) 
// 数值 攻击力 1677+3148=4826  暴击98.5  爆伤190.4 防御力:2580
// 46.6岩增伤   35普攻增伤(角斗士) 
// e开盾 10572
// q爆发 26365
// 普攻一套 78928
// 盾消失 36618
// 总 389272 

// 骨剑 510面板 27.6%暴击   50增伤(满层)
// 圣遗物 防御 岩伤 暴伤    副词条强化搭配  暴击率:46.8(12)  暴击伤害:101.4(13) 
// 数值 攻击力 1870  暴击98.9  爆伤244.8 防御力:1783
// 46.6岩增伤   35普攻增伤(角斗士) 
// e开盾 11661
// q爆发 30662
// 普攻一套 87294
// 盾消失 42587
// 总 434089 

// 钟离双岩增伤15 减抗性20  常驻效果  一般敌人10抗性 减为-10
// 骨剑 434089 -> 540380
// 假设班尼特+1000攻击力 并且持续15秒
// 骨剑 434089 -> 554174
// 假设莫娜提供增伤50 持续15秒
// 骨剑 434089 -> 531068
// 假设有辅助能提供30减防
// 骨剑 434089 -> 510693

// 难再有其他手段提升

let charaters = {
    nvpu : {
        name: "lv90女仆", 
        base: 191,
        criticalRate: 5,
        criticalStrike: 50,
        defence:799,
        defenceRate: 30
    }
}

let weapons = {
    wugong: {
        name:"lv90无工之剑",
        base: 608,
        attRate: 49.6 + 40  // 有护盾额外加40
    },
    tkDj: {
        name:"lv90天空之傲", // q后普攻8次攻击力x1.6 真空刃
        dmgRate: 16,
        base: 674,
        充能: 36.8
    },
    langmo: { 
        name:"lv90狼末",
        base: 608,
        attRate: 49.6 + 40   // 触发buff 额外加80
    },
    cg:{
        name:"lv90骨剑",
        base: 510,
        criticalRate: 27.6,
        dmgRate:50
    },
    by: {
        name:"lv90白影剑",
        base: 510,
        attRate: 48,
        defenceRate:99.7
    }
}
let defence_clips = calc_clips_normal();
let defence_clips2 = calc_clips_normal(2);
let charactersDmg = []

// 白影
charactersDmg.push(getDMG([charaters.nvpu,weapons.by,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,defenceRate:58.3},defence_clips], (data,second) => {
    // 角斗士x4
    data.attRate += 18;
    let attack = data.base * (1 + data.attRate/100) + data.fixedAtt
    let defence = data.defence*(1 + data.defenceRate/100)+data.fixedDef
    let defToAtt = defence * 1.22 // 防御力的 122%
    data.fixedAtt += defToAtt
    let qdmg = getDmgDps(data, 1.21+1.67) * q(10) * df(90,90);
    let dunMv = getDmgDps(data, 4) * q(10) * df(90,90);
    let admg = getDmgDps({...data,dmgRate:data.dmgRate+35}, 1.56+1.45+1.71+2.24) * q(10) * df(90,90);
    let edmg = getDmgDps({...data,base:data.defence,attRate:data.defenceRate,fixedAtt:data.fixedDef}, 2.16) * q(10) * df(90,90);
    let a1 = getDmgDps(data, 1.56) * q(10) * df(90,90);
    let ret = qdmg + admg*4 + dunMv + edmg;
    return {point:ret, data, second,defToAtt, a1, defence,qdmg, edmg,admg,dunMv,attack,lastattack:attack + defToAtt}
}))

// 天空
charactersDmg.push(getDMG([charaters.nvpu,weapons.tkDj,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,defenceRate:58.3},defence_clips], (data,second) => {
    // 角斗士x4
    data.attRate += 18;
    let attack = data.base * (1 + data.attRate/100) + data.fixedAtt
    let defence = data.defence*(1 + data.defenceRate/100)+data.fixedDef
    let defToAtt = defence * 1.22 // 防御力的 122%
    data.fixedAtt += defToAtt
    let qdmg = getDmgDps(data, 1.21+1.67) * q(10) * df(90,90);
    let dunMv = getDmgDps(data, 4) * q(10) * df(90,90);
    let admg = getDmgDps({...data,dmgRate:data.dmgRate+35}, 1.56+1.45+1.71+2.24) * q(10) * df(90,90);
    let edmg = getDmgDps({...data,base:data.defence,attRate:data.defenceRate,fixedAtt:data.fixedDef}, 2.16) * q(10) * df(90,90);
    let a1 = getDmgDps(data, 1.56) * q(10) * df(90,90);
    let zkr = getDmgDps({...data, dmgRate:16}, 1.6*8) * q(10) * df(90,90);
    let ret = qdmg + admg*4 + dunMv + edmg;
    return {point:ret, data, second,defToAtt, a1, defence,qdmg, edmg,admg,dunMv, zkr,attack,lastattack:attack + defToAtt}
}))

// 骨剑
charactersDmg.push(getDMG([charaters.nvpu,weapons.cg,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,defenceRate:58.3},defence_clips2], (data,second) => {
    // 角斗士x4
    data.attRate += 18;
    data.dmgRate += 15;
    let attack = data.base * (1 + data.attRate/100) + data.fixedAtt
    let defence = data.defence*(1 + data.defenceRate/100)+data.fixedDef
    let defToAtt = defence * 1.22 // 防御力的 122%
    data.fixedAtt += defToAtt
    let qdmg = getDmgDps(data, 1.21+1.67) * q(-10) * df(90,90);
    let dunMv = getDmgDps(data, 4) * q(-10) * df(90,90);
    let admg = getDmgDps({...data,dmgRate:data.dmgRate+35}, 1.56+1.45+1.71+2.24) * q(-10) * df(90,90);
    let edmg = getDmgDps({...data,base:data.defence,attRate:data.defenceRate,fixedAtt:data.fixedDef}, 2.16) * q(-10) * df(90,90);
    let a1 = getDmgDps(data, 1.56) * q(-10) * df(90,90);
    let ret = qdmg + admg*4 + dunMv + edmg;
    return {point:ret, data, second,defToAtt, a1, defence,qdmg, edmg,admg,dunMv,attack,lastattack:attack + defToAtt}
}))

// 狼末
charactersDmg.push(getDMG([charaters.nvpu,weapons.langmo,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,defenceRate:58.3},defence_clips], (data,second) => {
    // 角斗士x4
    data.attRate += 18;
    let defence = data.defence*(1 + data.defenceRate/100)+data.fixedDef
    let attack = data.base * (1 + data.attRate/100) + data.fixedAtt
    let defToAtt = defence * 1.22 // 防御力的 122%
    data.fixedAtt += defToAtt
    let qdmg = getDmgDps(data, 1.21+1.67) * q(10) * df(90,90);
    let dunMv = getDmgDps(data, 4) * q(10) * df(90,90);
    let admg = getDmgDps({...data,dmgRate:data.dmgRate+35}, 1.56+1.45+1.71+2.24) * q(10) * df(90,90);
    let edmg = getDmgDps({...data,base:data.defence,attRate:data.defenceRate,fixedAtt:data.fixedDef}, 2.16) * q(10) * df(90,90);
    let a1 = getDmgDps(data, 1.56) * q(10) * df(90,90);
    let ret = qdmg + admg*4 + dunMv + edmg;
    return {point:ret, data, second,defToAtt, a1, defence,qdmg, edmg,admg,dunMv,attack,lastattack:attack + defToAtt}
}))

// 狼末
charactersDmg.push(getDMG([charaters.nvpu,weapons.langmo,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,defenceRate:58.3},defence_clips], (data,second) => {
    // 角斗士x4
    data.attRate += (18+80);
    let defence = data.defence*(1 + data.defenceRate/100)+data.fixedDef
    let attack = data.base * (1 + data.attRate/100) + data.fixedAtt
    let defToAtt = defence * 1.22 // 防御力的 122%
    data.fixedAtt += defToAtt
    let qdmg = getDmgDps(data, 1.21+1.67) * q(10) * df(90,90);
    let dunMv = getDmgDps(data, 4) * q(10) * df(90,90);
    let admg = getDmgDps({...data,dmgRate:data.dmgRate+35}, 1.56+1.45+1.71+2.24) * q(10) * df(90,90);
    let edmg = getDmgDps({...data,base:data.defence,attRate:data.defenceRate,fixedAtt:data.fixedDef}, 2.16) * q(10) * df(90,90);
    let a1 = getDmgDps(data, 1.56) * q(10) * df(90,90);
    let ret = qdmg + admg*4 + dunMv + edmg;
    return {point:ret, data, second,defToAtt, a1, defence,qdmg, edmg,admg,dunMv,msg:"狼末buff",attack,lastattack:attack + defToAtt}
}))

// 无工
charactersDmg.push(getDMG([charaters.nvpu,weapons.wugong,{fixedAtt:311,criticalRate:31.1,dmgRate:46.6,defenceRate:58.3},defence_clips], (data,second) => {
    // 角斗士x4
    data.attRate += (18+40);
    let defence = data.defence*(1 + data.defenceRate/100)+data.fixedDef
    let defToAtt = defence * 1.22 // 防御力的 122%
    let attack = data.base * (1 + data.attRate/100) + data.fixedAtt
    data.fixedAtt += defToAtt
    let qdmg = getDmgDps(data, 1.21+1.67) * q(10) * df(90,90);
    let dunMv = getDmgDps(data, 4) * q(10) * df(90,90);
    let admg = getDmgDps({...data,dmgRate:data.dmgRate+35}, 1.56+1.45+1.71+2.24) * q(10) * df(90,90);
    let edmg = getDmgDps({...data,base:data.defence,attRate:data.defenceRate,fixedAtt:data.fixedDef}, 2.16) * q(10) * df(90,90);
    let a1 = getDmgDps(data, 1.56) * q(10) * df(90,90);
    let ret = qdmg + admg*4 + dunMv + edmg;
    return {point:ret, data, second,defToAtt, a1, defence,qdmg, edmg,admg,dunMv,msg:"无工buff",attack,lastattack:attack + defToAtt}
}))





console.log(charactersDmg.sort((a,b)=>b.point-a.point));


function getDMG(dataarr, getRet){
    let chance = 25;
    let _ret = [];
    for (let index = 0; index <= chance; index++) {
        let criticalStrike = index; 
        for (let index2 = 0; index2 <= chance - index; index2++) {
            let criticalRate = index2;
            for (let index3 = 0; index3 <= chance-index-index2; index3++) {
                let attRate = index3;
                let defenceRate = chance - index - index2 - index3;
                _ret.push({
                    defenceRate: 7.3 * defenceRate,
                    attRate:5.8 * attRate,
                    criticalRate:3.9 * criticalRate,
                    criticalStrike:7.8 * criticalStrike
                });
            }
        }
    }
    _ret = _ret.map(second => {
        let panel = getPanel([...dataarr, second]);
        return  getRet(panel, second)
    })
    _ret.sort((b,a)=> a.point-b.point)
    return _ret[0]
}

function getDmgDps(data, rate=1){
    let criticalRate = data.criticalRate
    if(criticalRate > 100){criticalRate = 100}
    let baseat = data.base * (1 + data.attRate/100) + data.fixedAtt;
    let bdmg = baseat * (1 + data.criticalStrike/100);
    let bdps = (criticalRate * 10 * bdmg + (1000-criticalRate * 10)*baseat)/1000
    let adddmg = bdps * (1 + data.dmgRate/100)
    return adddmg * rate
}

function getPanel(arr){
    let info = {name1:"",name2:""};
    arr.forEach((item, i)=>{
        if(item.name){
            info["name" + (i+1)] = item.name
        }
        for (const key in item) {
            if(key !== "name"){
                if(info[key]){
                    info[key] += item[key]
                } else {
                    info[key] = item[key]
                }
            }
        }
    })
    return info
}

function q (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}

function df(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}

// 固定攻击力 19  防御力23 生命值299 5.3% 
function calc_clips_normal (n) {
    let clips = [
        {
            attRate: 5.8,
            defenceRate: 7.3,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            attRate: 5.8,
            defenceRate: 7.3,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            attRate: 5.8,
            fixedDef: 23,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            attRate: 5.8,
            defenceRate: 7.3,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            attRate: 5.8,
            fixedDef: 23,
            defenceRate: 7.3,
            criticalRate:n!=2? 0:3.9,
            criticalStrike:n!=2? 7.8:0
        }
    ]
    let data = {}
    clips.forEach(item => {
        for (const key in item) {
            data[key] = data[key]? (data[key]+item[key]) : item[key]
        }
    })
    return data
}

